package com.neuedu.qian.controller;

import com.neuedu.qian.entity.Department;
import com.neuedu.qian.service.IDepartmentService;
import com.neuedu.qian.vo.ResponseData;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Log4j2
@RequestMapping("/qian/api/department")
@RestController
@Tag(name = "部门控制器")
public class DepartmentController {

    @Autowired
    @Qualifier("departmentService")
    private IDepartmentService departmentService;

    @Operation(summary = "添加员工表")
    @PostMapping("create")
    public ResponseData create(Department c) {
        return departmentService.insert(c);
    }

    @Operation(summary = "删除员工表")
    @DeleteMapping("deleteById/{depId}")
    public ResponseData deleteById(@PathVariable("depId") int depId) {
        boolean success = departmentService.removeById(depId);
        int rows = success ? 1 : 0;
        return ResponseData.success(rows);
    }

    @Operation(summary = "更改员工表")
    @PatchMapping("updateById")
    public ResponseData updateById(@RequestBody  Department c) {
        int row = departmentService.update(c);
        return ResponseData.success(row);
    }

    @Operation(summary = "查询员工表")
    @GetMapping("getById/{depId}")
    public ResponseData getById(@PathVariable("depId") int depId) {
        Department row = departmentService.getById(depId);
        return ResponseData.success(row);
    }

    @Operation(summary = "查询员工表")
    @GetMapping("queryList")
    public ResponseData queryList(Department depart) {
        List<Department> list = departmentService.selectList(depart);
        return ResponseData.success(list);
    }
}